import {Actions} from 'react-native-router-flux'
import { isLoggedIn } from '../services/token'

//在这里配置 受保护 的scene
const FORBIDDEN = ['priceHistory',]

const _navigate = (route, params) => {
  if (FORBIDDEN.includes(route) && !isLoggedIn()) {
    Actions.auth({params: {route, params}})
    return;
  }
  Actions[route](params)
}

const Router = {
  push (scene, params = {}) {
    params.type = 'push'
    _navigate(scene, params)
  },
  jump (scene, params = {}) {
    params.type = 'jump'
    _navigate(scene, params)
  },
  replace (scene, params = {}) {
    params.type = 'replace'
    _navigate(scene, params)
  },
  refresh(params = {}){
    Actions.refresh(params);
  },
  go (scene, params = {}) {
    _navigate(scene, params)
  },
  pop (params = {}) {
    Actions.pop(params)
  },
  toast (message, mode = 'danger') {
    Actions.toast(message, mode)
  }
}

export default Router